using UnityEngine;
using System.Collections;

public class MenuEntry : MonoBehaviour {
	
	static int sComptor = 0;
	static int sCurrentSelected = 0;
	
	static bool sWasChanged = false;
	
	public string GoTo;
	public int Index = 0;
	
	public LoadingScript LoadObj;
	
	private int mNumber;
	
	// Use this for initialization
	void Start () 
	{
		if(Index == 0)
		{
			sComptor = 0;
			sCurrentSelected = 0;
		}
		
		if(Index > sComptor)
			sComptor = Index;
		
		mNumber = Index;
	}
	
	void OnMouseEnter()
	{
		sCurrentSelected = mNumber;
	}
	
	void OnMouseDown()
	{
		if(GoTo != "")
		{
			Application.LoadLevel(GoTo);
		}
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(sCurrentSelected == mNumber)
			guiText.material.color = Color.red;
		else
			guiText.material.color  = Color.white;
		
		if(Input.GetAxis("Vertical") < 0 && !sWasChanged)
		{
			sWasChanged = true;
			sCurrentSelected++;
			
			if(sCurrentSelected > sComptor)
				sCurrentSelected = 0;
		}
		else if(Input.GetAxis("Vertical") > 0 && !sWasChanged)
		{
			sWasChanged = true;
			sCurrentSelected--;
			
			if(sCurrentSelected < 0)
				sCurrentSelected = sComptor;
		}
		else if(Input.GetAxis("Vertical") == 0)
		{
			sWasChanged = false;
		}
		
		if(Input.GetAxis("BOMB") > 0 && sCurrentSelected == mNumber)
		{
			OnMouseDown();
		}
	}
}
